﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.ComponentModel;

namespace PracaInz_v0
{
    class SingleTreeViewData : INotifyPropertyChanged
    {
        bool _treeLoaded = false;
        public bool TreeLoaded 
        {
            get { return this._treeLoaded; }
            set
            {
                this._treeLoaded = value;
                IsShowTreeEnable();
            }
        }

        bool _nodeVectSourceLoaded = false;
        public bool NodeVectSourceLoaded 
        {
            get { return this._nodeVectSourceLoaded; }
            set
            {
                this._nodeVectSourceLoaded = value;
                IsShowTreeEnable();
            }
        }

        bool _vectorsLoaded = false;
        public bool VectorsLoaded 
        {
            get { return this._vectorsLoaded; }
            set
            {
                this._vectorsLoaded = value;
                IsShowTreeEnable();
            } 
        }

        bool _showTree = false;
        public bool ShowTree
        {
            get { return this._showTree; }
            set
            {
                this._showTree = value;
                OnPropertyChanged("ShowTree");
            }
        }

        public DataTable Tree { get; set; }
        public DataTable NodeVectSource { get; set; }
        public DataTable Vectors { get; set; }

        void IsShowTreeEnable()
        {
            if (_vectorsLoaded && _nodeVectSourceLoaded && _treeLoaded)
                ShowTree = true;
        }

        #region PropertyChanged
        public event PropertyChangedEventHandler PropertyChanged = null;

        virtual protected void OnPropertyChanged(string propName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
        } 
        #endregion

        #region Instance
        SingleTreeViewData() { }

        private static volatile SingleTreeViewData instance;
        private static object syncRoot = new Object();

        public static SingleTreeViewData Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (syncRoot)
                    {
                        if (instance == null)
                            instance = new SingleTreeViewData();
                    }
                }
                return instance;
            }
        } 
        #endregion
    }
}
